<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>业财一体化平台</title>
    <link rel="stylesheet" href="${ctxPath}/plugins/layui/css/layui.css">
    <script src="${ctxPath}/plugins/layui/layui.js"></script>
  
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style rel="stylesheet" type="text/css">
        .layui-tab-title li:first-child > i {
            display: none;
        }
    </style>
    <style>
        body{
            background:url(${ctxPath}/img/bg.png) repeat-x;
            min-height: 600px;
            position: relative;
        }
        #sky{
            background: url(${ctxPath}/img/sky.png) repeat;
            width: 100%;
            heigth: 462px;
            z-index: -20;
            height: 462px;
            position: absolute;
            top: 0px;
        }
        .form-signin{
            top: 20%;
            width: 360px;
            position: absolute;
            right: 15%;
            height: 80%;
            margin: 0;
            background: #fff;
        }
        .form-signin-heading {
            color: #333;
            font-family: '楷体';
            margin-top: 80px;
            margin-bottom: 40px;
            font-size: 28px;
            font-weight: bold;
            text-align: center;
        }

        .buttom_line {
            width: 80%;
            height: 40px;
            margin: 18px auto;
            text-align: center;
            background: #fff;
        }
    </style>
</head>
<body class="layui-layout-body" >
<div id="sky"></div>
<div class="form-signin">
    <form class="layui-form" id="form"  action="${ctxPath}/login.do" method="post">
        <h1 class="form-signin-heading" >业财一体化平台</h1>

      <div class="layui-form-item buttom_line">
        <label class="layui-form-label" style="width: 15%">用户名</label>
        <div class="layui-input-block" style="width: 75%;  margin-left: 75px;">
          <input type="text" name="code" id="code" lay-verify="title" autocomplete="off" onBlur="autoTakeOrgId()"
            placeholder="请输入用户名" class="layui-input"   >
        </div>
      </div>

      <div class="layui-form-item buttom_line">
<!--        <label class="layui-form-label">密码</label>-->
          <label class="layui-form-label" style="width: 15%">密码</label>
        <div class="layui-input-block" style="width: 75%;  margin-left: 75px;">
          <input type="password" name="password" id="password" lay-verify="required"  name="" placeholder="请输入密码" autocomplete="off"
           class="layui-input">
        </div>
      </div>
        <div class="layui-form-item buttom_line">
<!--            <label class="layui-form-label">机构</label>-->
            <label class="layui-form-label" style="width: 15%">机构</label>
            <div class="layui-input-block" style="width: 75%;  margin-left: 75px;">
                <select name="orgId" id="orgId" lay-verify="required" lay-search="">
                    <option value="">请选择机构</option>
                </select>
            </div>
        </div>
      </form>
         <div class="layui-form-item" style="margin-top: 40px">
             <div class="layui-input-block">
                 <button class="layui-btn" onclick="check()">立即登录</button>
             </div>
         </div>
</div>
<script type="text/javascript">
    layui.use(['form', 'layedit', 'laydate'], function() {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
        var $ = layui.jquery;
    });
    function check() {
        var xmlhttp;
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                var error = xmlhttp.responseText;
                if(error=="0"){
                    var form =document.getElementById("form");
                    form.submit();
                }else if(error=="1"){
                    alert("用户不存在");
                }else if(error=="2"){
                    alert("用户密码错误");
                }else if(error=="3"){
                    alert("用户已经被锁定");
                }else if(error=="4"){
                    alert("用户已经失效");
                }else if(error=="5"){
                    alert("用户已经删除");
                }else if(error=="6"){
                    alert("用户与管理机构不一致");
                }else if(error=="7"){
                    alert("用户不在生效日期范围内");
                }
            }
        }

        var code = document.getElementById("code").value;
        var password = document.getElementById("password").value;
        var orgId = document.getElementById("orgId").value;
        var param = code+","+password+","+orgId+","
        var URL="${ctxPath}/check.do";
        xmlhttp.open("POST",URL,true);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send("param="+param);
    }

    //填写用户名自动带出机构
    function autoTakeOrgId() {
        var $ = layui.jquery;
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var code = document.getElementById("code").value;
        //页面一加载就发送ajax
        $.ajax({
            url: "${ctxPath}/admin/org/autoTakeOrgId.do",
            type: "post",
            data:{param:code},
            datType: "json",
            success: function (data) {
                //加载数据
                $("#orgId").html("");
                var html = "";
                html +="<option value=''>请选择机构</option>";
                if(data.code == 0){
                    dataList = data.data.coreOrgsList;
                    dataid = data.data.select.id;
                    for (var i = 0; i < dataList.length; i++) {
                        html += '<option value="' + dataList[i].id + '">'+dataList[i].code+'-'+dataList[i].name+'</option>'
                    }
                }
                $("#orgId").append(html);
                $("#orgId").val(dataid);
                form.render('select');//重点：重新渲染select
            }
        });
    }
</script>
</body>
</html>